package com.imay.live.adapter;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.imay.live.R;
import com.imay.live.helper.LevelHelper;
import com.imay.live.model.UserModel;
import com.imay.live.utils.GlideUtil;

/**
 * 动态的推荐列表的Adapter
 * Created by chan on 2017/5/2.
 */

public class DynamicsSuggestAdapter extends BaseQuickAdapter<UserModel, BaseViewHolder> {
    public DynamicsSuggestAdapter() {
        super(R.layout.item_dynamics_suggest_user);
    }

    @Override
    protected void convert(BaseViewHolder helper, UserModel item) {
        // VIP的显示图标
        int vip = item.getVip();
        int icon = LevelHelper.getVIPIcon(vip);
        if (icon == 0) {
            helper.setVisible(R.id.iv_item_dynamics_suggest_vip, false);
        } else {
            helper.setVisible(R.id.iv_item_dynamics_suggest_vip, true);
            helper.setImageResource(R.id.iv_item_dynamics_suggest_vip, icon);
        }

        View view = helper.getView(R.id.tv_item_dynamics_suggest_follow);
        if (item.isMyFollow()) {
            view.setSelected(true);
            view.setClickable(false);
            ((TextView) view).setText(view.getContext().getString(R.string.has_followed));
        }else{
            view.setSelected(false);
            view.setClickable(true);
            ((TextView) view).setText(view.getContext().getString(R.string.un_followed));
        }

        GlideUtil.loadCircleImage((ImageView) helper.getView(R.id.civ_item_dynamics_suggest_img),item.getImgHead(),R.mipmap.pnl_00_head108);
        TextView tvName = helper.getView(R.id.tv_item_dynamics_suggest_name);
        tvName.setText(item.getNick());

        if (item.getSex() == 1) {
            Bitmap bmp = BitmapFactory.decodeResource(helper.getConvertView().getResources(), R.mipmap.ico_00boy);
            Drawable drawable = new BitmapDrawable(bmp);
            drawable.setBounds(0, 0, bmp.getWidth(), bmp.getHeight());
            tvName.setCompoundDrawables(drawable, null, null, null);
        } else if (item.getSex() == 2) {
            Bitmap bmp = BitmapFactory.decodeResource(helper.getConvertView().getResources(), R.mipmap.ico_00girl);
            Drawable drawable = new BitmapDrawable(bmp);
            drawable.setBounds(0, 0, bmp.getWidth(), bmp.getHeight());
            tvName.setCompoundDrawables(drawable, null, null, null);
        }

        if (TextUtils.isEmpty(item.getCity()) || item.getCity().contains("kIMUserCity")) {
            helper.setText(R.id.tv_item_dynamics_suggest_location, R.string.str_dynamics_address);
        } else {
            helper.setText(R.id.tv_item_dynamics_suggest_location, item.getCity());
        }

        helper.addOnClickListener(R.id.civ_item_dynamics_suggest_img);
        helper.addOnClickListener(R.id.tv_item_dynamics_suggest_follow);
    }
}
